Skip to content

Conversation

@noahsmartin
Copy link
Contributor

@noahsmartin noahsmartin commented Nov 20, 2025

Adds a new protocol for integrations that takes dependencies as an input. For the easiest migration conformers of the protocol can satisfy the Dependencies associated type with just typealias Dependencies = SentryDependencyContainer. This PR shows how it can be used to make the dependencies just define the minimum necessary dependencies so it can be easily mocked in tests. There are a few benefits to this over the current objc protocol:

  • The protocol defines a failable initializer rather than a function returning a boolean. This means properties in the integration can be let constants rather than vars with default nil value. Making these immutable with help with a lot of swift properties like thread safety, and remove the need from handling null cases that should be unreachable.

  • The associatedtype for dependencies decouples the SentryDependencyContainer from the integration, so each integration only defines the dependencies it needs and doesn't have a reliance on a particular type providing those dependencies.

  • No need for @objc or even NSObject in the integration classes

#skip-changelog

Closes #6863

@noahsmartin noahsmartin added the ready-to-merge Use this label to trigger all PR workflows label Nov 20, 2025
@noahsmartin noahsmartin force-pushed the swiftIntegrations branch 2 times, most recently from ddc979e to 979af12 Compare November 20, 2025 19:26
@codecov
Copy link

codecov bot commented Nov 20, 2025

Codecov Report

❌ Patch coverage is 52.94118% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.845%. Comparing base (df7a9be) to head (91e9878).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...rations/UserFeedback/UserFeedbackIntegration.swift 33.333% 6 Missing ⚠️
...Feedback/SentryUserFeedbackIntegrationDriver.swift 0.000% 5 Missing ⚠️
.../Integrations/UserFeedback/SentryFeedbackAPI.swift 0.000% 4 Missing ⚠️
Sources/Swift/Core/Integrations/Integrations.swift 92.857% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #6862       +/-   ##
=============================================
+ Coverage   84.814%   84.845%   +0.030%     
=============================================
  Files          453       453               
  Lines        27619     27628        +9     
  Branches     12110     12122       +12     
=============================================
+ Hits         23425     23441       +16     
- Misses        3908      4140      +232     
+ Partials       286        47      -239     
Files with missing lines Coverage Δ
Sources/Sentry/SentryHub.m 96.268% <100.000%> (ø)
Sources/Sentry/SentrySDKInternal.m 85.020% <100.000%> (-0.121%) ⬇️
Sources/Swift/SentryDependencyContainer.swift 98.496% <ø> (ø)
Sources/Swift/Core/Integrations/Integrations.swift 92.857% <92.857%> (ø)
.../Integrations/UserFeedback/SentryFeedbackAPI.swift 0.000% <0.000%> (ø)
...Feedback/SentryUserFeedbackIntegrationDriver.swift 0.000% <0.000%> (ø)
...rations/UserFeedback/UserFeedbackIntegration.swift 33.333% <33.333%> (ø)

... and 40 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update df7a9be...91e9878. Read the comment docs.

@noahsmartin noahsmartin force-pushed the swiftIntegrations branch 3 times, most recently from b0d6dfe to 4a01fe6 Compare November 20, 2025 20:15
@github-actions
Copy link
Contributor

github-actions bot commented Nov 20, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1222.22 ms 1252.16 ms 29.94 ms
Size 24.14 KiB 1.02 MiB 1016.00 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
466e905 1223.78 ms 1256.70 ms 32.92 ms
102cf89 1218.31 ms 1239.78 ms 21.47 ms
7c7ac56 1225.90 ms 1250.22 ms 24.33 ms
41c0aa8 1222.75 ms 1262.40 ms 39.65 ms
73c9712 1238.57 ms 1260.38 ms 21.80 ms
162cd7f 1230.59 ms 1256.76 ms 26.16 ms
52603c5 1229.35 ms 1251.82 ms 22.47 ms
f97a070 1218.88 ms 1253.12 ms 34.24 ms
2a07609 1207.79 ms 1233.77 ms 25.98 ms
bbb9d5c 1234.24 ms 1261.76 ms 27.52 ms

App size

Revision Plain With Sentry Diff
466e905 23.75 KiB 1010.51 KiB 986.76 KiB
102cf89 23.74 KiB 891.02 KiB 867.27 KiB
7c7ac56 23.75 KiB 902.49 KiB 878.74 KiB
41c0aa8 23.75 KiB 986.80 KiB 963.05 KiB
73c9712 23.75 KiB 908.01 KiB 884.26 KiB
162cd7f 23.75 KiB 908.39 KiB 884.64 KiB
52603c5 23.75 KiB 969.66 KiB 945.92 KiB
f97a070 23.75 KiB 858.68 KiB 834.93 KiB
2a07609 23.75 KiB 912.78 KiB 889.03 KiB
bbb9d5c 24.15 KiB 1.01 MiB 1014.91 KiB

Previous results on branch: swiftIntegrations

Startup times

Revision Plain With Sentry Diff
9ef3a04 1217.35 ms 1248.14 ms 30.79 ms
f71365a 1222.02 ms 1248.70 ms 26.68 ms
c1ceeee 1218.08 ms 1245.14 ms 27.06 ms

App size

Revision Plain With Sentry Diff
9ef3a04 24.14 KiB 1.01 MiB 1015.52 KiB
f71365a 24.14 KiB 1.01 MiB 1015.45 KiB
c1ceeee 24.14 KiB 1.02 MiB 1016.82 KiB

@noahsmartin noahsmartin force-pushed the swiftIntegrations branch 2 times, most recently from a35d333 to 10b2476 Compare November 20, 2025 21:12
@noahsmartin noahsmartin marked this pull request as ready for review November 20, 2025 21:12
Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I'm unsure about this approach. I will have another look tomorrow, but here's what I already found.

@property (nullable, nonatomic, strong) SentrySession *session;

@property (nonatomic, strong) NSMutableArray<id<SentryIntegrationProtocol>> *installedIntegrations;
@property (nonatomic, strong) NSMutableArray<id> *installedIntegrations;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m: That really feels wrong to me. Integrations still must adhere to SentryIntegrationProtocol.

Suggested change
@property (nonatomic, strong) NSMutableArray<id> *installedIntegrations;
@property (nonatomic, strong) NSMutableArray<id<SentryIntegrationProtocol>> *installedIntegrations;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change they wouldn't have to anymore, because now they could adhere to Sentry.Integration which doesn't have an ObjC representation. We could still make some other base class or protocol that is visible to Swift, but I don't think it would provide any value. I'll add another commit demonstrating how we could still do this so we can talk about it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch @philipphofmann there was one place where ObjC code still tried to dynamically call one of the methods on SentryIntegrationProtocol. So we can't quite get rid of the objc compatibility yet. I updated it to have a base protocol defined in ObjC that has the one function ObjC needs to know about (close) and now the Swift protocol also requires conformance to this objc protocol.

let name: String

init<I: Integration>(_ integration: I.Type) where I.Dependencies == SentryDependencyContainer {
name = NSStringFromClass(I.self)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Generic Swift integration produces mangled name

Using NSStringFromClass on a generic Swift type like UserFeedbackIntegration<SentryDependencyContainer> returns a mangled, module-qualified name instead of a simple class name. This breaks trimmedInstalledIntegrationNames which expects names like "SentryUserFeedbackIntegration" but will receive something like "Sentry.UserFeedbackIntegration<Sentry.SentryDependencyContainer>". These trimmed names are sent to Sentry servers as part of SDK info, causing incorrect reporting of installed integrations.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge Use this label to trigger all PR workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ref: Use Swift integrations

3 participants